Trò chơi Halloween vui nhộn trong UNITY Engine
10.801 lượt xem;
- Score.cs
- ScoreManager /
- Scripts /
- Assets /
- project /
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class Score : MonoBehaviour {
6
7 public static Score instance;
8
9 private const string BEST_SCORE = "bestscore";
10
11 void Start () {
12 MakeSingleton();
13 GameStartedFirstTime();
14 }
15
16 void MakeSingleton() {
17 if (instance != null)
18 {
19 Destroy(gameObject);
20 }
21 else
22 {
23 instance = this;
24 DontDestroyOnLoad(gameObject);
25 }
26 }
27
28 void GameStartedFirstTime() {
29 if (!PlayerPrefs.HasKey("isGameStartedFirstTime"))
30 {
31 PlayerPrefs.SetInt(BEST_SCORE, 0);
32 PlayerPrefs.SetInt("isGameStartedFirstTime", 0);
33 }
34 }
35
36 public void SetHighScore(int score) {
37 PlayerPrefs.SetInt(BEST_SCORE, score);
38 }
39
40 public int GetHighScore() {
41 return PlayerPrefs.GetInt(BEST_SCORE);
42 }
43 }
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class Score : MonoBehaviour {
6
7 public static Score instance;
8
9 private const string BEST_SCORE = "bestscore";
10
11 void Start () {
12 MakeSingleton();
13 GameStartedFirstTime();
14 }
15
16 void MakeSingleton() {
17 if (instance != null)
18 {
19 Destroy(gameObject);
20 }
21 else
22 {
23 instance = this;
24 DontDestroyOnLoad(gameObject);
25 }
26 }
27
28 void GameStartedFirstTime() {
29 if (!PlayerPrefs.HasKey("isGameStartedFirstTime"))
30 {
31 PlayerPrefs.SetInt(BEST_SCORE, 0);
32 PlayerPrefs.SetInt("isGameStartedFirstTime", 0);
33 }
34 }
35
36 public void SetHighScore(int score) {
37 PlayerPrefs.SetInt(BEST_SCORE, score);
38 }
39
40 public int GetHighScore() {
41 return PlayerPrefs.GetInt(BEST_SCORE);
42 }
43 }